#import "sprite_game_enemy_0.h"

#import "mgr_game_physics.h"

@implementation SpriteGameEnemy0

- (id)initSpriteGameEnemy0
{
	if ((self = [super initSpriteGameEnemy]))
	{
		objectName_ = "object sprite game enemy type 0";

		/*box2d
		*/
		fixtureBody_ = NULL;
	}
	return self;
}

- (void)createBody
{
	int i;
	int _VertexCount;
	float _Ratio;
	b2Vec2 *_Vertex;
	b2PolygonShape _PolygonShape;
	b2FixtureDef _FixtureDef;

	[super createBody];

	_Ratio = 1 / CMgrGamePhysics::Ratio();
	_FixtureDef.density = 1.0f;
	_FixtureDef.isSensor = true;

	_VertexCount = g_CfgGameEnemyDataTable[0].box2d_collision_point_table_body.size();
	_Vertex = ptCreateCollisionVertex(&g_CfgGameEnemyDataTable[0].box2d_collision_point_table_body);
	for (i = 0; i < _VertexCount; ++i)
	{
		_Vertex[i] = ptScaleVector_same(_Vertex[i], _Ratio);
	}
	_PolygonShape.Set(_Vertex, _VertexCount);
	free(_Vertex);
	_FixtureDef.shape = &_PolygonShape;
	fixtureBody_ = box2dBody_->CreateFixture(&_FixtureDef);
}

- (void)destroyBody
{
	[super destroyBody];
	fixtureBody_ = NULL;
}

- (void)playAniMove
{
	CCAnimation *_Animation;
	id _ActionMove;
}

- (void)playAniAttack
{
	CCSequence *_SeqAttack;
	id _ActionAttack;
	CCCallFuncN *_CallBackAttack;
}

- (void)playAniDie
{
	CCSequence *_SeqDie;
	id _ActionDie;
	CCCallFuncN *_CallBackDie;
}

- (void)aiCreate
{
	switch (aiType_)
	{
	case ENEMY_AI_TYPE_0:
	case ENEMY_AI_TYPE_1:[self actionMovePath]; break;
	case ENEMY_AI_TYPE_2:[self actionMove]; break;
	}
}

- (void)aiActionMoveOver
{
	switch (aiType_)
	{
	case ENEMY_AI_TYPE_0:
		if (0 == movePath_.size())
		{
			CMgrGameMission::Instance()->EventEnemyDisappear(self);
		}
		else
		{
			[self actionStand:standTime_];
		}
		break;
	case ENEMY_AI_TYPE_1: assert(false); break;
	case ENEMY_AI_TYPE_2: [self actionStand:standTime_]; break;
	default: assert(false);
	}
}

- (void)actionMove
{
	CGPoint endPos;
	CCSequence *seq;
	id actionMove;
	CCCallFunc *callBack;
	
	endPos = CfgGameGetPointCGPoint(rand() % 9);
	actionMove = tcCreateActionMove(self.positionInPixels, endPos, [self GetMoveSpeed]);
	callBack = [CCCallFunc actionWithTarget:self selector:@selector(callBackActionMoveOver)];
	seq = [CCSequence actions:actionMove, callBack, nil];
	[self runAction:seq];
}

- (void)actionToturial
{
	id _Action;
	CCCallFunc *_CallBack;
	CCSequence *_Seq;

	[self stopAction];
	[self playAni:ENEMY_ANI_MOVE];

	_Action = tcCreateActionMove(self.positionInPixels, g_CfgGameScrrenArea[7].center, 500);
	_CallBack = [CCCallFunc actionWithTarget:self selector:@selector(callBackActionToturialOver)];
	_Seq = [CCSequence actions:_Action, _CallBack, nil];
	[self runAction:_Seq];
}

- (void)callBackActionToturialOver
{
	CMgrGameMission::Instance()->ToturialEnemyMoveOver();
}

@end